/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.tels;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.tels.TMsgSend;
import com.server.modules.sys.service.tels.TMsgSendService;

/**
 * 短信发送Controller
 * @author 金小敏
 * @version 2017-03-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/tels/tMsgSend")
public class TMsgSendController extends BaseController {

	@Autowired
	private TMsgSendService tMsgSendService;
	
	@ModelAttribute
	public TMsgSend get(@RequestParam(required=false) String id) {
		TMsgSend entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tMsgSendService.get(id);
		}
		if (entity == null){
			entity = new TMsgSend();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:tels:tMsgSend:view")
	@RequestMapping(value = {"list", ""})
	public String list(TMsgSend tMsgSend, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TMsgSend> page = tMsgSendService.findPage(new Page<TMsgSend>(request, response), tMsgSend); 
		model.addAttribute("page", page);
		model.addAttribute("tMsgSend", tMsgSend);
		return "modules/sys/tels/tMsgSendList";
	}

	@RequiresPermissions("sys:tels:tMsgSend:view")
	@RequestMapping(value = "form")
	public String form(TMsgSend tMsgSend, Model model) {
		model.addAttribute("tMsgSend", tMsgSend);
		return "modules/sys/tels/tMsgSendForm";
	}

	@RequiresPermissions("sys:tels:tMsgSend:edit")
	@RequestMapping(value = "save")
	public String save(TMsgSend tMsgSend, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tMsgSend)){
			return form(tMsgSend, model);
		}
		tMsgSendService.save(tMsgSend);
		addMessage(redirectAttributes, "保存短信发送成功");
		return "redirect:"+Global.getAdminPath()+"/sys/tels/tMsgSend/?repage";
	}
	
	@RequiresPermissions("sys:tels:tMsgSend:edit")
	@RequestMapping(value = "delete")
	public String delete(TMsgSend tMsgSend, RedirectAttributes redirectAttributes) {
		tMsgSendService.delete(tMsgSend);
		addMessage(redirectAttributes, "删除短信发送成功");
		return "redirect:"+Global.getAdminPath()+"/sys/tels/tMsgSend/?repage";
	}

}